package com.apts.constant;

import com.jfinal.kit.Prop;

/**
 * 项目常量初始化赋值
 * 
 * @author lwh
 * @date 2016-03-15
 */
public final class AppBaseConstant extends Prop {
	
	private static AppBaseConstant prop = null;
	
	public AppBaseConstant(String fileName) {
		super(fileName);
	}
	
	/**
	 * 常量初始化配置, 首次初始化才有效
	 * @author lwh
	 * @param fileName 加载配置文件设置项目全局常量
	 * @date 2016-03-15
	 */
	public static void initConstant(String fileName) {
		if( prop == null ){
			prop = new AppBaseConstant(fileName);
		}
	}
	
	/**
	 *  获取某一常量值
	 * @param property	属性名
	 * @param c	return返回的类型
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getValue(String property, Class<T> c){
		if( c == String.class ){
			return (T)prop.get(property);
		}
		if( c == Integer.class ){
			return (T)prop.getInt(property);
		}
		if( c == Long.class ){
			return (T) prop.getLong(property);
		}
		if( c == Boolean.class ){
			return (T)prop.getBoolean(property);
		}
		return null;
	}

}
